package elsa.bootmapper;

import elsa.bean.ScsDoc;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface DocMapper {

    //查询文档条数(所有)
    @Select("select count(*) from scs_doc where docnum = #{docnum,jdbcType=VARCHAR}")
    int findDocCount(@Param("docnum") String docnum);

    //查询文档列表(所有)
    @Select("select docname, uploadtime, state from scs_doc where docnum = #{docnum,jdbcType=VARCHAR} order by latesttime desc")
    List<ScsDoc> findAllDoc(@Param("docnum") String docnum);

    //查询文档信息
    @Select("select docnum, docname, doc1, doc2, doc3, doc4, doc5, doc6, doc7, doc8, uploader, uploadtime, ycschick, txr, txrtime, state from scs_doc where docnum = #{docnum,jdbcType=VARCHAR} and uploadtime = #{uploadtime,jdbcType=VARCHAR}")
    ScsDoc findDocInfo(@Param("docnum") String docnum, @Param("uploadtime") String uploadtime);

    //新建文档-船厂上传
    @Insert("insert into scs_doc (docnum, docname, doc1, doc2, doc3, doc4, doc5, doc6, doc7, doc8, uploader, uploadtime, state, latesttime) values (#{docnum,jdbcType=VARCHAR}, #{docname,jdbcType=VARCHAR}, #{doc1,jdbcType=VARCHAR}" +
            ", #{doc2,jdbcType=VARCHAR}, #{doc3,jdbcType=VARCHAR}, #{doc4,jdbcType=VARCHAR}, #{doc5,jdbcType=VARCHAR}, #{doc6,jdbcType=VARCHAR}, #{doc7,jdbcType=VARCHAR}, #{doc8,jdbcType=VARCHAR}," +
            " #{uploader,jdbcType=VARCHAR}, #{uploadtime,jdbcType=VARCHAR}, #{state,jdbcType=VARCHAR}, #{latesttime})")
    void saveDoc(ScsDoc scsDoc);

    //更新文档-船厂上传
    @Update("update scs_doc set docname = #{docname,jdbcType=VARCHAR},doc1 = #{doc1,jdbcType=VARCHAR},doc2 = #{doc2,jdbcType=VARCHAR},doc3 = #{doc3,jdbcType=VARCHAR}," +
            "doc4 = #{doc4,jdbcType=VARCHAR},doc5 = #{doc5,jdbcType=VARCHAR},doc6 = #{doc6,jdbcType=VARCHAR},doc7 = #{doc7,jdbcType=VARCHAR},doc8 = #{doc8,jdbcType=VARCHAR},uploadtime = #{atime,jdbcType=VARCHAR},latesttime = #{latesttime}" +
            " where docnum = #{docnum,jdbcType=VARCHAR} and uploadtime = #{uploadtime,jdbcType=VARCHAR}")
    void updateDocCc(ScsDoc scsDoc);

    //更新文档-验船师审核
    @Update("update scs_doc set ycschick = #{ycschick,jdbcType=VARCHAR},txr = #{txr,jdbcType=VARCHAR},txrtime = #{txrtime},state = #{state,jdbcType=VARCHAR},latesttime = #{latesttime} where docnum = #{docnum,jdbcType=VARCHAR} and uploadtime = #{uploadtime,jdbcType=VARCHAR}")
    void updateDocYcs(ScsDoc scsDoc);

    //删除文档(单个)
    @Delete("delete from scs_doc where docnum = #{docnum,jdbcType=VARCHAR} and uploadtime = #{uploadtime,jdbcType=VARCHAR}")
    void deleteDoc(@Param("docnum") String docnum, @Param("uploadtime") String uploadtime);

    //删除文档(多个)
    @Delete("delete from scs_doc where docnum = #{docnum,jdbcType=VARCHAR}")
    void deleteDocAll(@Param("docnum") String docnum);
}
